﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using dll_DynamicDataDisplay.ViewModels;
using dll_DynamicDataDisplay.ViewModels.DispElement;

namespace Sample_ChartPlotter
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window, INotifyPropertyChanged
    {

        /// <summary>
        /// 图表
        /// </summary>
        public Vm_Chart Chart
        {
            get { return _Chart; }
            set
            {
                if (_Chart != value)
                {
                    _Chart = value;
                    this.OnPropertyChanged("Chart");
                }
            }
        }
        private Vm_Chart _Chart = new Vm_Chart();

        /// <summary>
        /// 曲线
        /// </summary>
        public Vm_Element_Curve Curve
        {
            get { return _Curve; }
            set
            {
                if (_Curve != value)
                {
                    _Curve = value;
                    this.OnPropertyChanged("Curve");
                }
            }
        }
        private Vm_Element_Curve _Curve = new Vm_Element_Curve() { Stroke_Brush = Brushes.Green };

        /// <summary>
        /// 竖线
        /// </summary>
        public Vm_Element_VerLine VerLine
        {
            get { return _VerLine; }
            set
            {
                if (_VerLine != value)
                {
                    _VerLine = value;
                    this.OnPropertyChanged("VerLine");
                }
            }
        }
        private Vm_Element_VerLine _VerLine = new Vm_Element_VerLine() { Stroke_Brush = Brushes.Red };

        /// <summary>
        /// 横线
        /// </summary>
        public Vm_Element_HorLine HorLine
        {
            get { return _HorLine; }
            set
            {
                if (_HorLine != value)
                {
                    _HorLine = value;
                    this.OnPropertyChanged("HorLine");
                }
            }
        }
        private Vm_Element_HorLine _HorLine = new Vm_Element_HorLine() { Stroke_Brush = Brushes.Blue };

        public MainWindow()
        {
            InitializeComponent();

            Chart.ElementCollection.Add(Curve);
            //Chart.ElementCollection.Add(VerLine);
            Chart.ElementCollection.Add(HorLine);
        }


        #region NotifyPropertyChanged

        public event PropertyChangedEventHandler PropertyChanged;
        public virtual void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        #endregion

        private void btnChangeVisible_Click(object sender, RoutedEventArgs e)
        {
            
        }

        private void btnInit_Click(object sender, RoutedEventArgs e)
        {
            Random r = new Random();

            int num = 1024;

            Point[] pArr = new Point[num];
            for (int i = 0; i < num; i++)
            {
                pArr[i] = new Point(i , r.NextDouble());
            }

            Curve.Points = pArr;

            List<double> listX = new List<double>(Curve.Points.Length);
            List<double> listY = new List<double>(Curve.Points.Length);
            foreach (var item in Curve.Points)
            {
                listX.Add(item.X);
                listY.Add(item.Y);
            }

            //VerLine.Value = listX.Average();
            HorLine.Value = listY.Average();
        }
    }
}
